#ifndef COMMANDEXECUTOR_H
#define COMMANDEXECUTOR_H

#include <QObject>
#include <QProcess>

class CommandExecutor : public QObject
{
    Q_OBJECT
public:
    explicit CommandExecutor(QString cmd, QObject *parent = nullptr);
    ~CommandExecutor();
    void start();

    int getExitCode() const;
    QString getStdout();
    QString getStderr();
    static QString exec(QString cmd);

private:
    QString cmd;
    QString cmdStdout;
    QString cmdStderr;
    QProcess *process = nullptr;
    int exitCode = 0;

signals:
    /**
      安装结束
     * @brief finishedEvent
     */
    void finishedEvent();

public slots:
    void onReadStandardOutput();
    void onReadStandardError();
    void onFinished(int, QProcess::ExitStatus);
};

#endif // COMMANDEXECUTOR_H
